﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Enums;
using Xenta.Operations;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class CatalogCategoryTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [Test]
        public void Can_CRUD()
        {
            var category = Processor.Execute(new CreateCatalogCategory
            {
                ParentID = 0
            }).Result;

            Assert.NotNull(category);
            category.AreEqual(Processor.Execute(new GetCatalogCategory
            {
                EntityID = category.EntityID
            }).Result);

            var upd_category = Processor.Execute(new UpdateCatalogCategory
            {
                EntityID = category.EntityID,
                Flags = CatalogCategoryFlags.Active
            }).Result;

            Assert.NotNull(upd_category);
            upd_category.AreEqual(category);
            upd_category.Flags.AreEqual(CatalogCategoryFlags.Active);

            Processor.Execute(new DeleteCatalogCategory
            {
                EntityID = category.EntityID
            });
        }

        [Test]
        public void Can_Manage_Attribute_Relations()
        {
            var category = Processor.Execute(new CreateCatalogCategory
            {
                ParentID = 0
            }).Result;
            var attribute = Processor.Execute(new CreateLookupAttribute
            {
                Flags = LookupAttributeFlags.Active
            }).Result;

            Processor.Execute(new MapLookupAttributeToCatalogCategory
            {
                EntityID = category.EntityID,
                ChildID = attribute.EntityID
            }).Result
            .Attributes.DoesContain(attribute);

            Processor.Execute(new UnmapLookupAttributeFromCatalogCategory
            {
                EntityID = category.EntityID,
                ChildID = attribute.EntityID
            }).Result
            .Attributes.DoesNotContain(attribute);
        }
    }
}
